//package com.telit.firecommand.service.impl;
//
//import cn.hutool.core.date.DateUtil;
//import com.telit.android.dto.GeoPkFdiRdAreaDto;
//import com.telit.common.entity.DataReturn;
//import com.telit.common.enums.ResultCode;
//import com.telit.common.exception.ForestBaseException;
//import com.telit.common.util.DateUtils;
//import com.telit.dispose.feign.RemoteDisposeService;
//import com.telit.dispose.vo.resourceManagement.ResourceCategoryVO;
//import com.telit.firecommand.constant.FireConstant;
//import com.telit.firecommand.dao.FireQueryDao;
//import com.telit.firecommand.dto.VisualLeftDTO;
//import com.telit.firecommand.dto.VisualRightDTO;
//import com.telit.firecommand.enums.FireDjType;
//import com.telit.firecommand.service.CameraInfoService;
//import com.telit.firecommand.service.CommForestryConditionService;
//import com.telit.firecommand.service.VisualService;
//import com.telit.firecommand.vo.*;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//
//import java.math.BigDecimal;
//import java.text.DecimalFormat;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * Create by Chencf 2023/02/17
// */
//@Service
//public class VisualServiceImpl implements VisualService {
//
//    @Autowired
//    private CommForestryConditionService commForestryConditionService;
//
//    @Autowired
//    private RemoteDisposeService disposeFeignClient;
//
//    @Autowired
//    private CameraInfoService cameraInfoService;
//
//    @Autowired
//    private ForesterService  foresterService;
//
//    @Autowired
//    private FireQueryDao fireQueryDao;
//
//    @Value("${not.fire.time:2023-02-20}")
//    private String notFireTime;
//
//    @Value("${visual.statis.hlyNum:1364}")
//    private Integer hlyNum;
//
//    @Value("${visual.statis.cfzrNum:2634}")
//    private Integer cfzrNum;
//
//    @Value("${visual.statis.zzrqNum:1317}")
//    private Integer zzrqNum;
//
//    @Value("${visual.statis.wgslNum:345}")
//    private Integer wgslNum;
//
//
//
//    @Override
//    public VisualLeftVO visualLeft(VisualLeftDTO dto) {
//        VisualLeftVO visualLeftVO = new VisualLeftVO();
//        List<Map> condListMaps = new ArrayList<>();
//        //step 1 查询林情概况
//        CommForestryConditionsVO conditionsByDistrictCode = commForestryConditionService.findConditionsByDistrictCode(dto.getDistrictCode());
//        Map<String , Object >slmj  = new HashMap<>();
//        slmj.put("resourceName","森林面积");
//        slmj.put("resourceCode","slmj");
//        slmj.put("resourceNum",conditionsByDistrictCode.getSlmj());
//        HashMap<String , String >slfgl  = new HashMap<>();
//        slfgl.put("resourceName","森林覆盖率");
//        slfgl.put("resourceCode","slfgl");
//        slfgl.put("resourceNum",conditionsByDistrictCode.getSlfgl());
//        HashMap<String , String >slxjl  = new HashMap<>();
//        slxjl.put("resourceName","森林蓄积量");
//        slxjl.put("resourceCode","slxjl");
//        slxjl.put("resourceNum",conditionsByDistrictCode.getSlxjl());
//       condListMaps.add(slmj);
//       condListMaps.add(slfgl);
//       condListMaps.add(slxjl);
//
//        //step 2 查询防火物资
//        DataReturn<List<ResourceCategoryVO>> listDataReturn = disposeFeignClient.topFloorDownChildrenList(Long.parseLong("0"), null, null, null, dto.getDistrictCode());
//        if (!ResultCode.SUCCESS.getCode().equals(listDataReturn.getCode())
//                && !FireConstant.ALARMS_SUCCESS_CODE.equals(listDataReturn.getCode())) {
//            throw new ForestBaseException(listDataReturn.getErrorMsg());
//        }
//        List<CommFireResourceVO> resourceVOList = new ArrayList<>();
//        List<ResourceCategoryVO> voList = listDataReturn.getData();
//        //过滤医疗资源数据
//          voList = voList.stream().filter(resourceCategoryVO -> !resourceCategoryVO.getResourceName().contains("医疗")).collect(Collectors.toList());
//        //拿到下面数量
//        for (ResourceCategoryVO vo:voList){
//            CommFireResourceVO commFireResourceVO = new CommFireResourceVO();
//            commFireResourceVO.setResourceNum(vo.getCategoryNum());
//            if (vo.getResourceName().contains("机构人员")) {
//                commFireResourceVO.setResourceCode("jgry");
//            }
//            if (vo.getResourceName().contains("基础设施")) {
//                commFireResourceVO.setResourceCode("jcss");
//            }
//            if (vo.getResourceName().contains("阻隔系统")) {
//                commFireResourceVO.setResourceCode("zgxt");
//            }
//            if (vo.getResourceName().contains("重点目标")) {
//                commFireResourceVO.setResourceCode("zdmb");
//            }
//            commFireResourceVO.setResourceName(vo.getResourceName());
//            //根据资源大类查询资源
//            commFireResourceVO.setImage(vo.getImg());
//            resourceVOList.add(commFireResourceVO);
//        }
//
//        //stpe 2  网格相关数据
//        List<CommWlVO> commWlVO = new ArrayList<>();
//           //查询护林员
//        CommWlVO hly = new CommWlVO();
//        int countByCondition = foresterService.countByCondition(dto.getDistrictCode(), null, null);
//        hly.setResourceName("护林员");
//        hly.setResourceCode("hly");
//        hly.setResourceNum(hlyNum);
//        //查询群众义务扑火队
//        CommWlVO phd = new CommWlVO();
//        phd.setResourceName("群众义务扑火队队长");
//        phd.setResourceCode("phdz");
//        voList = voList.stream().filter(resourceCategoryVO -> resourceCategoryVO.getResourceName().contains("机构人员")).collect(Collectors.toList());
//        phd.setResourceNum(voList.get(0).getCategoryNum());
//
//        // 下面数量为产品指定数量
//        CommWlVO sqfzr = new CommWlVO();
//        sqfzr.setResourceName("村(社区)责任人");
//        sqfzr.setResourceCode("cfzr");
//        sqfzr.setResourceNum(cfzrNum);
//
//        CommWlVO jdfzr = new CommWlVO();
//        jdfzr.setResourceName("镇(街道)负责区");
//        jdfzr.setResourceCode("zzrq");
//        jdfzr.setResourceNum(zzrqNum);
//
//        CommWlVO wgsl = new CommWlVO();
//        wgsl.setResourceName("网格数量");
//        wgsl.setResourceCode("wgsl");
//        wgsl.setResourceNum(wgslNum);
//
//        commWlVO.add(hly);
//        commWlVO.add(phd);
//        commWlVO.add(sqfzr);
//        commWlVO.add(jdfzr);
//        commWlVO.add(wgsl);
//
//
//
//
//        //TODO 未实现
//        visualLeftVO.setCommForestryConditionsVO(condListMaps);
//        visualLeftVO.setCommFireResourceVO(resourceVOList);
//        visualLeftVO.setCommWlVO(commWlVO);
//        return visualLeftVO;
//
//    }
//
//    @Override
//    public VisualMiddleVO visualMiddle(VisualLeftDTO dto) {
//        if (StringUtils.isNotBlank(dto.getDistrictCode())){
//            dto.setDistrictCode("5101");
//        }
//        VisualMiddleVO vo = new VisualMiddleVO();
//          //查询视频监控
//        int countCamera = cameraInfoService.countCamera(dto.getDistrictCode(), null, null);
//        //查询无人机
//        int countUav = commForestryConditionService.countUav(dto.getDistrictCode());
//
//        //查询护林员
//        int countByCondition = foresterService.countByCondition(dto.getDistrictCode(), null, null);
//       vo.setCameraNum(countCamera);
//       vo.setUavNum(countUav);
//       vo.setForestNum(1364);
//
//       //监控覆盖的区域
//        BigDecimal bigDecimal = commForestryConditionService.cameraScope(dto.getDistrictCode());
//        vo.setCameraScope(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).toString());
//        return vo;
//    }
//
//    @Override
//    public VisualRightVO visualRight(VisualRightDTO dto) {
//
//        DecimalFormat df = new DecimalFormat("0.00");
//        VisualRightVO vo = new VisualRightVO();
//        vo.setNotFireTime(notFireTime);
//        //火险等级
//        List<GeoPkFdiRdAreaDto> geoPkFdiRdAreaDtos = commForestryConditionService.statisticAreaByDJ(dto);
//        geoPkFdiRdAreaDtos.forEach(geoPkFdiRdAreaDto -> geoPkFdiRdAreaDto.setDjName(
//                geoPkFdiRdAreaDto.getDjName()+"火险("+ FireDjType.code2Str(geoPkFdiRdAreaDto.getDjName())+")"));
//       //卫星过境时间
//        vo.setFireLevelVO(geoPkFdiRdAreaDtos);
//        Date date = DateUtils.getDate(dto.getDate(), DateUtils.DATE_FORMAT);
//        Date beginOfDay = DateUtil.beginOfDay(date);
//        Date endOfDay = DateUtil.endOfDay(date);
//
//        //监控动态在线率  在线监控/总数量
//        int allCamera = cameraInfoService.countCamera(dto.getDistrictCode(), null, null);
//        int onlineCamera= cameraInfoService.countCamera(dto.getDistrictCode(), null, "1");
//        vo.setCameraOnline(onlineCamera);
//        vo.setCameraAll(allCamera);
//        if ((onlineCamera==0)||(allCamera==0)){
//            vo.setCameraOnlineRate("0.00");
//        }else {
//
//            String cameraOnlineRate = df.format((float)onlineCamera/allCamera);
//            vo.setCameraOnlineRate(cameraOnlineRate);
//        }
//        //告警推送
//        int countFireAlarm = fireQueryDao.countFireAlarm(dto.getDistrictCode(), 1,null,beginOfDay,endOfDay);
//         vo.setAlarmPush(countFireAlarm);
//        //巡护动态在线率  在线护林员/护林员总
//        int countByCondition = foresterService.countByCondition(dto.getDistrictCode(), null, null);
//        int onlineForester = foresterService.countByCondition(dto.getDistrictCode(), 1, null);
//        if (onlineCamera==0||onlineForester==0){
//            vo.setForestRate("0.00");
//        }else {
//            String forestRate = df.format((float)onlineForester/countByCondition);
//            vo.setForestRate(forestRate);
//        }
//        //事件上报---->预警监测业务系统的护林员上报的火情
//        int eventPush = fireQueryDao.countFireAlarm(dto.getDistrictCode(), 1,"2",beginOfDay,endOfDay);
//        vo.setEventPush(eventPush);
//
//        //整理卫星过境时间（初步设想是系统时间往前推4个小时）
//        Date satelliteTime = DateUtil.beginOfDay(new Date());
//        Date date1 = DateUtils.addHour(satelliteTime, 14);
//        vo.setSatelliteTime(DateUtils.getDate(date1,DateUtils.yyyy_MM_dd_HH_mm_ss));
//        return vo;
//    }
//}
